/**
 * output package name
 */
package com.kingdee.eas.custom.hr.compensation.client;

import java.awt.event.*;
import java.sql.SQLException;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.ui.face.CoreUIObject;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.dao.query.ISQLExecutor;
import com.kingdee.bos.dao.query.SQLExecutorFactory;
import com.kingdee.eas.framework.*;
import com.kingdee.eas.hr.base.BaseException;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.bos.metadata.entity.SelectorItemInfo;
import com.kingdee.eas.basedata.org.OrgBlankException;
import com.kingdee.eas.common.client.OprtState;
import com.kingdee.eas.common.client.UIContext;
import com.kingdee.eas.custom.hr.compensation.AllowanceFactory;
import com.kingdee.eas.custom.hr.compensation.AllowanceTreeInfo;
import com.kingdee.jdbc.rowset.IRowSet;
import com.kingdee.util.StringUtils;

/**
 * output class name
 */
public class AllowanceEditUI extends AbstractAllowanceEditUI
{
    private static final Logger logger = CoreUIObject.getLogger(AllowanceEditUI.class);
    
    /**
     * output class constructor
     */
    public AllowanceEditUI() throws Exception
    {
        super();
    }
    /**
     * output loadFields method
     */
    public void loadFields()
    {
        super.loadFields();
    }

    /**
     * output storeFields method
     */
    public void storeFields()
    {
        super.storeFields();
    }


    protected IObjectValue createNewData()
    {
    	com.kingdee.eas.custom.hr.compensation.AllowanceInfo AllowanceInfo = new com.kingdee.eas.custom.hr.compensation.AllowanceInfo();
    	AllowanceInfo.setCreator((com.kingdee.eas.base.permission.UserInfo)(com.kingdee.eas.common.client.SysContext.getSysContext().getCurrentUser()));
    	AllowanceInfo.setTreeid((AllowanceTreeInfo)getUIContext().get("ParentNode"));
    	prmtAllowanceType.setData(AllowanceInfo.getTreeid());
        return AllowanceInfo;
    }

    
    protected ICoreBase getBizInterface() throws Exception
    {
        return AllowanceFactory.getRemoteInstance();
    }
    

    protected void verifyInput(ActionEvent e)
        throws Exception
    {
        if(StringUtils.isEmpty(editData.getNumber()))
        {
            txtNumber.requestFocusInWindow();
            throw new OrgBlankException(OrgBlankException.NUMBER_CAN_NOT_BLANK);
        }
        if(StringUtils.isEmpty(editData.getName()))
        {
            txtName.requestFocusInWindow();
            throw new OrgBlankException(OrgBlankException.NAME_CAN_NOT_BLANK);
        }
        if(prmtAllowanceType.getData() == null)
            throw new BaseException(BaseException.DIPLOMATYPE_NOT_NULL);
        if(isNotExistType())
            throw new BaseException(BaseException.DIPLOMYTYPE_NOT_EXIST);
        else
            return;
    }

    private boolean isNotExistType()throws BOSException, SQLException
    {
        boolean result = true;
        String sql = "select * from T_COM_AllowanceTREE where fname_l2 = '" + prmtAllowanceType.getData().toString() + "'";
        IRowSet rs = null;
        ISQLExecutor exector = SQLExecutorFactory.getRemoteInstance(sql);
        for(rs = exector.executeSQL(); rs.next();)
            result = false;

        return result;
    }

    protected void initWorkButton()
    {
        super.initWorkButton();
        initDiplomaTypeF7();
    }

    private void initDiplomaTypeF7()
    {
    	prmtAllowanceType.setQueryInfo("com.kingdee.eas.custom.hr.compensation.app.AllowanceTypeQuery");
    	prmtAllowanceType.setEditFormat("$number$");
    	prmtAllowanceType.setCommitFormat("$number$");
    	prmtAllowanceType.setDisplayFormat("$name$");
        EntityViewInfo env = new EntityViewInfo();
        FilterInfo filterLeaf = new FilterInfo();
        filterLeaf.getFilterItems().add(new FilterItemInfo("isLeaf", new Boolean(true)));
        env.setFilter(filterLeaf);
        prmtAllowanceType.setEntityViewInfo(env);
    }

   public void actionCopy_actionPerformed(ActionEvent e)
        throws Exception
    {
        super.actionCopy_actionPerformed(e);
        editData.setTreeid((AllowanceTreeInfo)getUIContext().get("ParentNode"));
        prmtAllowanceType.setData(editData.getTreeid());
    }


    /**
     * output setDataObject method
     */
    public void setDataObject(IObjectValue dataObject) 
    {
        super.setDataObject(dataObject);
        if(STATUS_ADDNEW.equals(getOprtState())) {
            editData.put("treeid",(com.kingdee.eas.custom.hr.compensation.AllowanceTreeInfo)getUIContext().get(UIContext.PARENTNODE));
        }
    }

    
 

}